*********************************************************************
*** Electoral Cycles in Government Policy Making:
*** Strategic Timing of Austerity Reform Measures in Western Europe
*** British Journal of Political Science
*** Stata replication do-file
*** Authors: Strobl, Daniel; Angelova, Mariyana; Bäck, Hanna; Müller, Wolfgang C.
*** Correspondence: wolfgang.mueller@univie.ac.at
*** Date: 2019-02-05
*********************************************************************

/*
Description of main variables (for in-depth description see main text):
-----------------------------------------------------------------------
austerityMeasure: Dummy variable indicating whether an austerity measure was introduced in a given month (DV)
timeRemaining: Percentage of time remaining in the legislative term (main IV)
sumOther: count of other social and taxation measures NOT classified as austerity measures
newPM: Dummy variable indicating cabinets with a new prime minister
mwc: Dummy variable indicating minimal winning cabinets
crisis: Dummy variable indicating cabinets with an economic crisis at the beginning of term
unempChangeLag: Yearly lag of change in unemployment rate
gdpLag: Yearly lag of change in GDP
debtChangeLag: Yearly lag of change in domestic debt as percentage of GDP
t: Time elapsed since the last austerity measure (in months)
cabid: unique cabinet ID
duration: Total cabinet duration (in days)
*/

clear
set more off

/* Set your working directory and start logging */
* cd "..."
* log "Electoral_Cycles_replication.smcl"

/* Load the dataset */
use "Electoral_Cycles_Strobl2019.dta"

************************************
* Regression analysis (Models 1-5) *
************************************

/* Model 1: Linear effect */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model1

/* Model 2: Curvilinear effect */
logit austerityMeasure sumOther c.timeRemaining##c.timeRemaining  c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model2

/* Model 3: New PM interaction */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM c.timeRemaining#i.crisis /// 
unempChangeLag gdpLag debtChangeLag c.timeRemaining#i.crisis c.t##c.t##c.t i.cabid if duration > 365, or
est sto model3

/* Model 4: MWC interaction */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.mwc c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model4

/* Model 5: New PM * MWC interaction */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
c.timeRemaining#i.crisis unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model5

****************
* Descriptives *
****************

est restore model5
bysort lastElection: egen meanAusterity = mean(sumAusterity) if e(sample)

preserve
	keep if e(sample)
	twoway lowess meanAusterity timeRemaining, ///
	lpattern(solid) ytitle("Average number of austerity measures") xtitle("Time remaining in legislative term (%)") ///
	aspect(1) legend(off) graphregion(color(white)) name(meanAusterity, replace) || ///
	scatter meanAusterity timeRemaining, xscale(reverse) ///
	msymbol(circle_hollow) mcolor(black) plotregion(lstyle(foreground)) ylabel(, nogrid) title("Austerity measures")
restore


*************************************
* Graphs of predicted probabilities *
*************************************

/* Linear & curvilinear time effect (Models 1 & 2) */
local title = "Linear time effect (Model 1)"
forval i=1/2 {
	est restore model`i'
	qui margins, at (timeRemaining=(0(1)100))
	marginsplot, plotopts(recast(line)) xscale(reverse) ylabel(0(.05).27, nogrid) ciopts(recast(rarea) fcolor(%60) lwidth(none)) ///
	  title(`title') xtitle("Time remaining in legislative term (%)") ///
	  aspect(1) legend(off) graphregion(color(white)) plotregion(lstyle(foreground)) ///
	  ytitle("Probability of austerity measures") name(model`i', replace)
	graph close model`i'
	local title = "Curvilinear time effect (Model 2)"
}
graph combine model1 model2, graphregion(color(white))

/* Interaction effects (Models 3 & 4) */
est restore model3
qui margins, at (timeRemaining=(0(1)100) newPM =(0 1))
marginsplot, plotopts(recast(line)) xscale(reverse) ylabel(0(.05).30, nogrid) ///
  ciopts(recast(rarea) lwidth(none)) plot1opts(lpattern(dash)) ci1opts(fcolor(%20)) ci2opts(fcolor(%60)) ///
  title("Prime minister change (Model 3)") xtitle("Time remaining in legislative term (%)") ///
  aspect(1) graphregion(color(white)) plotregion(lstyle(foreground)) ///
  ytitle("Probability of austerity measures") name(model3, replace)

est restore model4
qui margins, at (timeRemaining=(0(1)100) mwc=(0 1))
marginsplot, plotopts(recast(line)) xscale(reverse) ylabel(0(.05).30, nogrid) ///
  ciopts(recast(rarea) lwidth(none)) plot1opts(lpattern(dash)) ci1opts(fcolor(%20)) ci2opts(fcolor(%60)) ///
  title("Cabinet type (Model 4)") xtitle("Time remaining in legislative term (%)") ///
  aspect(1) graphregion(color(white)) plotregion(lstyle(foreground)) ///
  ytitle("Probability of austerity measures") name(model4, replace)

graph combine model3 model4, graphregion(color(white))

/* Conditional models (Model 5) */
est restore model5
local title = "No new prime minister"
forval i=0/1 {
	qui margins, at (timeRemaining=(0(1)100) mwc = (0 1) new=`i')
	marginsplot, plotopts(recast(line)) xscale(reverse) ylabel(0(.2).67, nogrid) ///
	  ciopts(recast(rarea) lwidth(none)) plot1opts(lpattern(dash)) ci1opts(fcolor(%20)) ci2opts(fcolor(%60)) ///
	  title(`title') xtitle("Time remaining in legislative term (%)") ///
	  aspect(1) graphregion(color(white)) plotregion(lstyle(foreground)) ///
	  ytitle("Probability of austerity measures") name(model5_new`i', replace)
	graph close model5_new`i'
	local title = "New prime minister"
}
graph combine model5_new0 model5_new1, graphregion(color(white))

***********************
* Output (Models 1-5) *
***********************
esttab model1 model2 model3 model4 model5, ///
label eform se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles drop(*cabid)

est restore model5
estpost tabstat austerityMeasure t sumOther timeRemaining unempChangeLag gdpLag debtChangeLag ///
  crisis newPM mwc if e(sample), columns(statistics) stats(n mean sd min p50 max)
esttab, replace cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2))") label


***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~***
*** Online supplementary information ***
***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~***

*********************************************************
* Alternative cabinet-level interactions (Models A1-A5) *
*********************************************************

gen majority = govSeatShare > .5 & govSeatShare < .
gen singleParty = numberParties == 1

/* Model A1 & A6: Single party vs. coalition governments */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
c.timeRemaining#i.singleParty c.timeRemaining#i.newPM#i.singleParty c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_single1

logit austerityMeasure sumOther timeRemaining ///
c.timeRemaining#i.singleParty c.timeRemaining#i.crisis ///
c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_single2

/* Model A2 & A7: Majority vs minority governments */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
c.timeRemaining#i.majority c.timeRemaining#i.newPM#i.majority c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_majority1

logit austerityMeasure sumOther timeRemaining ///
c.timeRemaining#i.majority c.timeRemaining#i.crisis  ///
c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_majority2

/* Model A3 & A8: DPI checks variable */
/* To run these models, please download the DPI2017.dta dataset and place in working directory: */
/* https://publications.iadb.org/en/publication/database-political-institutions-2017-dpi2017 */
preserve
	decode country, gen(countryname)
	replace countryname = "FRG/Germany" if countryname == "Germany"
	merge m:m countryname year using "DPI2017.dta"
	drop if _merge == 2

	logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
	c.timeRemaining#c.checks c.timeRemaining#i.newPM#c.checks c.timeRemaining#i.crisis ///
	unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
	est sto mod_checks1
		
	logit austerityMeasure sumOther timeRemaining ///
	c.timeRemaining#c.checks c.timeRemaining#i.crisis ///
	c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
	unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
	est sto mod_checks2
restore

/* Model A4 & A9: Number of government parties */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
c.timeRemaining#c.numberParties c.timeRemaining#i.newPM#c.numberParties c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_number1

logit austerityMeasure sumOther timeRemaining ///
c.timeRemaining#c.numberParties c.timeRemaining#i.crisis ///
c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_number2

/* Model A5 & A10: Ideological range */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
c.timeRemaining#c.rileRange c.timeRemaining#i.newPM#c.rileRange c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_range1

logit austerityMeasure sumOther timeRemaining ///
c.timeRemaining#c.rileRange c.timeRemaining#i.crisis ///
c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_range2

/* Output: Models A1-A10 */
esttab mod_single2 mod_majority2 mod_checks2 mod_number2 mod_range2, ///
label se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles replace eform drop(*cabid)
esttab mod_single1 mod_majority1 mod_checks1 mod_number1 mod_range1, ///
label se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles replace eform drop(*cabid)


**********************************************
* Alternative cabinet types (Models A11-A12) *
**********************************************

/* Model A11: Cabinet type interaction (MWC vs. minority governments vs. surplus coalitions) */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#ib2.ParlGov_type c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_types1

/* Model A12: NewPM * Cabinet type interaction */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM ///
  c.timeRemaining#ib2.ParlGov_type c.timeRemaining#i.newPM#ib2.ParlGov_type ///
  c.timeRemaining#i.crisis unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_types2

/* Output: Models A11-A12 */
esttab mod_types1 mod_types2, ///
label se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles replace eform drop(*cabid)


***************************************************
* Conditional logit specifcation (Models A13–A17) *
***************************************************

/* Model A13: Linear effect */
clogit austerityMeasure sumOther timeRemaining c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t if duration > 365, or group(cabid)
est sto clogit_model1

/* Model A14: Curvilinear effect */
clogit austerityMeasure sumOther c.timeRemaining##c.timeRemaining  c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t if duration > 365, or group(cabid)
est sto clogit_model2

/* Model A15: New PM interaction */
clogit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM c.timeRemaining#i.crisis /// 
unempChangeLag gdpLag debtChangeLag c.timeRemaining#i.crisis c.t##c.t##c.t if duration > 365, or group(cabid)
est sto clogit_model3

/* Model A16: MWC interaction */
clogit austerityMeasure sumOther timeRemaining c.timeRemaining#i.mwc c.timeRemaining#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t if duration > 365, or group(cabid)
est sto clogit_model4

/* Model A17: New PM * MWC interaction */
clogit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc ///
c.timeRemaining#i.crisis unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t if duration > 365, or group(cabid)
est sto clogit_model5

/* Output: Models A13-A17 */
esttab clogit_model1 clogit_model2 clogit_model3 clogit_model4 clogit_model5, ///
label eform se b(3) scalar(ll aic) sfmt(0) nomtitles replace 


*****************************************************************
* Please contact the authors for replication of Models A18-A21. *
*****************************************************************

***************************************************************
* Months until the next actual election date (Models A22–A26) *
***************************************************************

/* Model A22: Linear effect */
logit austerityMeasure sumOther nextElection c.nextElection#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model_next1

/* Model A23: Curvilinear effect */
logit austerityMeasure sumOther c.nextElection##c.nextElection  c.nextElection#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model_next2

/* Model A24: New PM interaction */
logit austerityMeasure sumOther nextElection c.nextElection#i.newPM c.nextElection#i.crisis /// 
unempChangeLag gdpLag debtChangeLag c.nextElection#i.crisis c.t##c.t##c.t i.cabid if duration > 365, or
est sto model_next3

/* Model A25: MWC interaction */
logit austerityMeasure sumOther nextElection c.nextElection#i.mwc c.nextElection#i.crisis ///
unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model_next4

/* Model A26: New PM * MWC interaction */
logit austerityMeasure sumOther nextElection c.nextElection#i.newPM c.nextElection#i.mwc c.nextElection#i.newPM#i.mwc ///
c.nextElection#i.crisis unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto model_next5

/* Output: Models A22-A26 */
esttab model_next1 model_next2 model_next3 model_next4 model_next5, ///
label eform se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles replace  drop(*cabid)


********************************************
* Ideological alternation (Models A27–A28) *
********************************************

/* Model A27: Model 5 with ideological alternation instead of new prime minister */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#c.alternationCMP ///
  c.timeRemaining#i.mwc c.timeRemaining#c.alternationCMP#i.mwc ///
  c.timeRemaining#i.crisis unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_alternation1

margins, dydx(timeRemaining) at (alternationCMP=(-35(5)45))
marginsplot, plotopts(recast(line)) ///
	ytitle("Average marginal effect of the time remaining in leg. term") title("") ///
	xtitle("Ideological alternation") xlabel(-40(10)50) ylabel(,nogrid) yline(0) plotregion(lstyle(foreground)) aspect(1) 

/* Model A28: Model 5 with ideological alternation and new prime minister */
logit austerityMeasure sumOther timeRemaining c.timeRemaining#i.newPM c.timeRemaining#c.alternationCMP ///
  c.timeRemaining#i.mwc c.timeRemaining#i.newPM#i.mwc c.timeRemaining#c.alternationCMP#i.mwc c.timeRemaining#i.crisis ///
  unempChangeLag gdpLag debtChangeLag c.t##c.t##c.t i.cabid if duration > 365, or
est sto mod_alternation2

/* Output: Models A27-A28 */
esttab mod_alternation1 mod_alternation2, ///
label se b(3) scalar(ll aic) sfmt(0) noomitted nomtitles replace eform drop(*cabid)

est restore mod_alternation2
local title = "No new prime minister"
forval i=0/1 {
	qui margins, at (timeRemaining=(0(1)100) mwc = (0 1) new=`i')
	marginsplot, plotopts(recast(line)) xscale(reverse) ylabel(0(.2).67, nogrid) ///
	  ciopts(recast(rarea) lwidth(none)) plot1opts(lpattern(dash)) ci1opts(fcolor(%20)) ci2opts(fcolor(%60)) ///
	  title(`title') xtitle("Time remaining in legislative term (%)") aspect(1) graphregion(color(white)) plotregion(lstyle(foreground))  ///
	  ytitle("Probability of austerity measures") name(model5_new`i', replace)
	graph close model5_new`i'
	local title = "New prime minister"
}
graph combine model5_new0 model5_new1, title("Austerity reform measures") graphregion(color(white))
